#-*- coding: utf8 -*-
from tutor.scripts import *
from tutor.plugins.sympy import *

bignum = 50
n_iter = 0
def rand():
    return One * oneof(1, 2, 3, 4, 5, 6, 8, 9, 12, 18) / 6

def test_OK(n):
    a, b = n.as_numer_denom()
    if a < bignum and b < bignum:
        return True
    else:
        return False

iter = 0
while True:
    # parâmetros iniciais
    with display_block('Entradas'):
        a = rand()
        b = a + rand()
        a, b = oneof((a, b), (b, a))
        r = rand() * oneof(-1, 1)
        s = rand() * oneof(-1, 1)
        Fx = r * y
        Fy = s * x

    with display_block('Resultados, comprimento'):
        correta = A * sqrt(B ** 2 + w ** 2) / B
        semModulo = -A
        semModuloNeg = A
        semDerivada = A / B
        semDerivadaModulo = A * (B + w) / (B * B + w * w)

    with display_block('Resultados, comprimento'):
        work = a * b * (r - s) / 2
        workNeg = -work
        wDiagE = -a * b * (3 * s + r) / 2
        wDiagENeg = -wDiagE
        wDiagO = -a * b * (r + s) / 2
        wDiagONeg = -wDiagO

    resps = set([work, workNeg, wDiagE, wDiagENeg, wDiagO, wDiagONeg])
    distr = set([])
    while len(distr) < 2:
        aux = oneof(*resps)
        aux *= rand()
        if aux not in resps:
            distr.add(aux)

    with display_block('Distratores'):
        dis1, dis2 = distr

    iter += 1

    if len(resps) < 6:
        print 'Repetidas...'
        continue

    if all(test_OK(x) for x in resps):
        break

print 'Número de iterações: ', iter
